package p4;

import java.util.ArrayList;

public class MinMax {

	private static void print_rec( ArrayList<Integer> a, int n ){
		if (n==0)
			return;
		print_rec( a, n-1 );
		System.out.print( " " + a.get(n-1) );
	}
	private static void print_rec( ArrayList<Integer> a ){
		print_rec( a, a.size() );
	}

	private static Integer smallest( ArrayList<Integer> a, int n ){
		Integer current = a.get(n-1); 
		if (n==1)
			return current;
		Integer minOfRest = smallest( a, n-1 );
		if (current <= minOfRest )
			return current;
		else
			return minOfRest;
	}
	private static Integer smallest( ArrayList<Integer> a ){
		return smallest( a, a.size() );
	}

	private static Integer largest( ArrayList<Integer> a ){
		return -1;
	}

	public static void main(String[] args) {
		ArrayList<Integer> a = new ArrayList<Integer>();
		final int size = 5;
		
		for (int i=0; i<size; i++)
			a.add( (int) (Math.random() * 10) );

		System.out.print("List is:  [ ");
		print_rec( a );
		System.out.println(" ]");
		System.out.println();

		System.out.print("Smallest thing in the list is:  " + smallest(a) );
		System.out.println();

		System.out.print("Largest  thing in the list is:  " + largest(a) );
		
	}
}
